package com.example.mvp.view

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.mvp.presenter.IBasePresenter

abstract class BaseActivity<T: IBasePresenter<V>, V: IBaseView>: AppCompatActivity(), IBaseView{
    protected var presenter: T? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        presenter = createPresenter()
        @Suppress("UNCHECKED_CAST")
        presenter?.onAttachView(this as V)

        lifecycle.addObserver(presenter!!)
    }

    override fun onDestroy() {
        super.onDestroy()
        presenter?.onDetachView()
    }

    abstract fun createPresenter(): T
}